package com.haste.controller;

import com.haste.pojo.CommonResult;
import com.haste.pojo.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {
    @Resource
    private RestTemplate restTemplate;
    public static final String PAYMENT_URL = "http://PAYMENT8001";
    @Resource
    private DiscoveryClient discoveryClient;
    @PostMapping("/order/save")
    public CommonResult save(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/save/",payment,CommonResult.class);
    }

    @GetMapping("/order/detail/{id}")
    public CommonResult detail(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/detail/"+id,CommonResult.class);
    }

    @GetMapping("/order/list")
    public CommonResult list(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/list/",CommonResult.class);
    }

}
